﻿@model IEnumerable<WeProjects.Models.ProjectViewModel>

<style type="text/css">
    .table {
        margin-top:20px;
    }
   .table tr.mainTask td {
        padding-bottom:2px;
    }
</style>

@{
    ViewBag.Title = "Index";
    int usrId=int.Parse(Membership.GetUser().ProviderUserKey.ToString());
}
<h2>项目列表</h2>
<p class="buttonIn">
    @if (Roles.IsUserInRole("sysadmin"))
    {
        @Html.ActionLink("建立(主)项目", "Create")
    }
</p>


<table class="table">
@foreach (var item in Model.Where(i => i.ParentID ==null))
{ 
    <tr class="mainTask">
        <td style="background-color: #dedede;">
            &nbsp;&nbsp;@Html.ActionLink(item.Title,"Details",new{ id=item.ID}) &nbsp;&nbsp;(编号:@Html.DisplayFor(modelItem => item.SerialNumber))
        </td>
        <td style="background-color: #dedede;"> 
                  @*@if (Roles.IsUserInRole("sysadmin") || item.OwnerID==usrId) { 
                      @Html.ActionLink("建立（子）项目", "Create", new { id = item.ID })
                  }*@
            @{
                string projOwnerDspName = "";
                if(item.OwnerID!=null)
                {
                    projOwnerDspName = item.OwnerDisplayName;                    
                }
            }
            @Html.Label(projOwnerDspName) (负责人)
         </td>
        <td style="background-color: #dedede;">    
            @*@if (Roles.IsUserInRole("sysadmin") || item.OwnerID==usrId) {
                @Html.ActionLink("发布新闻", "../News/Create", new { id = item.ID })
              }*@
            @{
                string currentTaskDesc="";
                var task = item.Tasks.Where(t => DateTime.Compare(Utility.IgnoreTime(t.Due.Value), Utility.IgnoreTime(DateTime.Now)) >= 0).FirstOrDefault();
                if(task!=null)
                {
                    currentTaskDesc=task.Description;
                }
            }
            @Html.Label(currentTaskDesc)（当前任务）
        </td>
        <td style="background-color: #dedede;">
            @Html.ActionLink("详细", "Details", new { id = item.ID }, new { @class = "btn btn-success btn-small" })&nbsp;
@if (Roles.IsUserInRole("sysadmin") || item.OwnerID==usrId) {
            @Html.ActionLink("编辑", "Edit", new { id = item.ID }, new { @class = "btn btn-success btn-small" })<span>&nbsp;</span>
            @Html.ActionLink("删除", "Delete", new { id = item.ID }, new { @class = "btn btn-danger btn-small" })
}
        </td>
    </tr>
    <tr><td colspan="3"></td></tr>
    @*以下显示大项目下的子项目*@
    foreach(var item1 in Model.Where(i=>i.ParentID==item.ID))
    {
        <tr class="subTask">            
            <td >
                &nbsp;&nbsp; &nbsp;&nbsp; @Html.ActionLink(item1.Title, "Details", new {id=item1.ID })&nbsp;&nbsp;(编号:@Html.DisplayFor(modelItem => item1.SerialNumber))
            </td>
            <td>
                @*@if (Roles.IsUserInRole("sysadmin") || item1.OwnerID == usrId)
                    {@Html.ActionLink("成员管理", "Member", new { id = item1.ID })}*@
                @{
                    if (item1.OwnerID != null)
                    {
                        projOwnerDspName = item1.OwnerDisplayName;
                    }
                    else
                    { projOwnerDspName = ""; }
                }
                @Html.Label(projOwnerDspName) 
            </td>
            <td>
@*@if (Roles.IsUserInRole("sysadmin") || item1.OwnerID == usrId){
                        @Html.ActionLink("发布新闻", "../News/Create", new { id = item1.ID })}*@
                @{
                    task = null; currentTaskDesc = "";                  
                    task = item1.Tasks.Where(t=>t.Due!=null).OrderBy(t=>t.Due).Where(t => DateTime.Compare(Utility.IgnoreTime(t.Due.Value),Utility.IgnoreTime(DateTime.Now)) >= 0).FirstOrDefault();
                    if (task != null)
                    {
                        currentTaskDesc = task.Description;
                    }
                }
                @Html.Label(currentTaskDesc)
            </td>
            <td>@Html.ActionLink("详细", "Details", new { id = item1.ID }, new { @class = "btn btn-success btn-small" })&nbsp;
@if (Roles.IsUserInRole("sysadmin")) {
                @Html.ActionLink("编辑", "Edit", new { id = item1.ID }, new { @class = "btn btn-success btn-small" })<span>&nbsp;</span>
                @Html.ActionLink("删除", "Delete", new { id = item1.ID }, new { @class = "btn btn-danger btn-small" })
}
            </td>
        </tr>
}
         <tr><td colspan="3" style="border-width:0"></td></tr>
}

</table>
